"""
@Time ： 2021/11/12 14:15
@Auth ： ChenZhangKun
"""
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome(r'D:\sofwares\chrom\chromedriver.exe')
driver.implicitly_wait(5)
driver.get('http://cdn1.python3.vip/files/selenium/test1.html')

# 选择html下的body标签
element = driver.find_element(By.XPATH, "/html/body")
print(element.get_attribute("outerHTML"))

# div下的所有元素
elements = driver.find_elements(By.XPATH, "/div/*")
for el in elements:
    print(el.get_attribute("outerHTML"))

# 所有id=west的元素
elements = driver.find_elements(By.XPATH, "//*[@id='west']")
for el in elements:
    print(el.get_attribute("outerHTML"))

# 选择select下class=single_choice的元素
elements = driver.find_elements(By.XPATH, "//select[@class='single_choice']")
for el in elements:
    print(el.get_attribute("outerHTML"))
# 要选择 style属性值 包含 color 字符串的 页面元素
elements = driver.find_elements(By.XPATH, "//*[contains(@style,'color')]")
for el in elements:
    print(el.get_attribute("outerHTML"))